﻿//
// Created by Administrator on 2022/6/15.
//

#include "NotificationIcon.h"
#include "MyDialog.h"

#include <wx/menu.h>

const int NotificationIcon::PopupExitID = wxID_HIGHEST + 1;

NotificationIcon::NotificationIcon( MyDialog *mainFrame ) : wxTaskBarIcon(){
    this->mainFrame = mainFrame;
    this->SetIcon( wxIcon( wxT("logo")));
}

NotificationIcon::~NotificationIcon()= default;

void NotificationIcon::OnLeftDoubleClick(wxTaskBarIconEvent &event){
    if( mainFrame->IsShown() ){
        mainFrame->Show(false );
    }else{
        mainFrame->Show(true );
        mainFrame->ToggleWindowStyle (wxSTAY_ON_TOP);
    }
}

wxMenu* NotificationIcon::CreatePopupMenu(){
    auto *popup = new wxMenu;

    popup->AppendSeparator();
    popup->Append(PopupExitID, wxT("E&xit"));
    return popup;
}

void NotificationIcon::OnQuit(wxCommandEvent& WXUNUSED(event)){
    /*
    if(mainFrame) {
        mainFrame->Close(false);
    }*/
    if ( wxMessageBox(wxT("确定要退出吗"), wxT("请确认"),
                      wxICON_QUESTION | wxYES_NO ) == wxYES ){
        RemoveIcon();
        ExitProcess( 0 );
    }
}


BEGIN_EVENT_TABLE(NotificationIcon, wxTaskBarIcon)
                EVT_TASKBAR_LEFT_DCLICK(NotificationIcon::OnLeftDoubleClick)
                EVT_MENU(PopupExitID, NotificationIcon::OnQuit)
END_EVENT_TABLE()